﻿using Clothes.IDAL;
using Clothes.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clothes.DAL
{
    public class CLLoginDAL : BaseDAL<CLLogin>, CLLoginIDAL
    {
        ClothesContext db = new ClothesContext();
        /// <summary>
        /// 通过用户名查找登录信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public CLLogin FindByUserName(string userName)
        {
            ClothesContext dbContext = new ClothesContext();
            return dbContext.CLLogin.SingleOrDefault(m => m.UserName == userName);
        }

        /// <summary>
        /// 通过手机号查找登录信息
        /// </summary>
        /// <param name="mobileNumber">手机号</param>
        /// <returns></returns>
        public CLLogin FindByMobileNumber(string mobileNumber)
        {
            ClothesContext dbContext = new ClothesContext();
            return dbContext.CLLogin.SingleOrDefault(m => m.MobileNumber == mobileNumber);
        }

        /// <summary>
        /// 判断用户名是否存在
        /// </summary>
        /// <param name="Name">用户名</param>
        /// <returns></returns>
        public bool LoginName(string Name)
        {
            ClothesContext db = new ClothesContext();
            var a1= db.CLLogin.Any(a => a.UserName == Name);
            return a1;
        }

        /// <summary>
        /// 判断手机号是否存在
        /// </summary>
        /// <param name="Number">手机好</param>
        /// <returns></returns>
        public bool LoginNumber(string Number)
        {
            
            return db.CLLogin.Any(a => a.MobileNumber == Number);
        }

        /// <summary>
        /// 根据手机号和密码查找信息
        /// </summary>
        /// <param name="mobileNumber"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public CLLogin Select(string mobileNumber, string password)
        {
            return db.CLLogin.SingleOrDefault(a => a.MobileNumber == mobileNumber && a.Password == password);

        }

        /// <summary>
        /// 根据姓名和密码查找信息
        /// </summary>
        /// <param name="mobileNumber"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        CLLogin CLLoginIDAL.SelectSource(string UserName, string password)
        {
            return db.CLLogin.SingleOrDefault(a => a.UserName == UserName && a.Password == password);
        }
    }
}
